﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Globalization;

namespace WpfApplication2.Validation
{
    public class CharSet : ValidationRule
    {
        public CharSet()
        {
        }

        private string charsAllowed;
        public string CharsAllowed
        {
            get
            {
                return charsAllowed;
            }
            set
            {
                charsAllowed = value;
            }
        }

        private Char[] Chars
        {
            get
            {
                return CharsAllowed.ToCharArray();
            }
        }

        
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if (value != null)
            {
                string valor = (String)value;

                foreach (Char item in valor)
                {
                    if (!Chars.Contains(item))
                        return new ValidationResult(false, "El valor es inválido!");
                }
                return new ValidationResult(true, null);
            }
            return new ValidationResult(true, null);
        }
    }
}
